//
//  LTLKeyboard.m
//  WeiBo
//
//  Created by Apple_Lzzy46 on 16/11/10.
//  Copyright © 2016年 LTL. All rights reserved.
//

#import "LTLKeyboard.h"
#import "LTLExpression.h"
#import "LTLExpressionTool.h"

@interface LTLKeyboard ()<LTLExpressionToolDelegate,LTLExpressionDelegate>

@property(nonatomic ,strong) LTLExpression *expression;
@property(nonatomic ,strong) LTLExpressionTool *expressionTool;

@end

@implementation LTLKeyboard
#pragma mark - 懒加载
-(LTLExpression *)expression
{
    if (!_expression) {
        _expression = [[LTLExpression alloc]init];
        _expression.delegate = self;
        
    }
    return _expression;
}
-(LTLExpressionTool *)expressionTool
{
    if (!_expressionTool) {
        _expressionTool = [[LTLExpressionTool alloc]init];
        _expressionTool.delegate = self;
    }
    return _expressionTool;
}
//添加控件
-(instancetype)initWithFrame:(CGRect)frame
{
    if (self == [super initWithFrame:frame]) {
        [self addSubview: self.expression];
        [self addSubview: self.expressionTool];
    }
    return self;
}
//布局
-(void)layoutSubviews
{
    [super layoutSubviews];
    [_expression mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(self.mas_top);
        make.left.equalTo(self.mas_left);
        make.right.equalTo(self.mas_right);
        make.bottom.equalTo(self.mas_bottom).offset(-36);
        
    }];
    [_expressionTool mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(_expression.mas_bottom);
        make.left.equalTo(self.mas_left);
        make.right.equalTo(self.mas_right);
        make.bottom.equalTo(self.mas_bottom);
        
    }];
}
/**
 *
 LTLExpressionTool代理方法
 
 LTLExpressionTypeLately = 0,//最近
 LTLExpressionTypeDefault,//默认
 LTLExpressionTypeEmoji,//emoji
 LTLExpressionTypeLxh,//emoj
 */
-(void)LTLExpressionTool:(LTLExpressionTool *)toolbar didClickBtn:(LTLExpressionType)type
{

    switch (type) {
        case LTLExpressionTypeLately:
            ///-1是因为LTLExpressionType从1开始,防止viewWithTag 方法查Tag为0时崩溃
            _expression.section = LTLExpressionTypeLately-1;
            break;
        case LTLExpressionTypeDefault:
            self.expression.section = LTLExpressionTypeDefault-1;
           
            break;
        case LTLExpressionTypeEmoji:
            _expression.section = LTLExpressionTypeEmoji-1;
            
            break;
        case LTLExpressionTypeLxh:
            _expression.section = LTLExpressionTypeLxh-1;
            
            
            break;
        
        default:
            break;
    }

}

/**
 //切换表情类型时调用
 @param section 表情类型
 */
-(void)LTLExpressionSection:(NSInteger)section
{
    //+1是因为LTLExpressionType从1开始,防止viewWithTag 方法查Tag为0时崩溃
    _expressionTool.Type = section+1;
}
@end
